﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="NewPinDialog.xaml.cs" company="Mar3ek">
//   This code is licensed under the Mozilla Public License 2.0.
//   You can find the full license text at the following address:
//   https://winkee.codeplex.com/license
// </copyright>
// <summary>
//   Defines the NewPinDialog type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace WinKee.Dialogs
{
    using System;

    using Windows.UI.Popups;
    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Controls;

    public sealed partial class NewPinDialog
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="NewPinDialog"/> class.
        /// </summary>
        public NewPinDialog()
        {
            this.InitializeComponent();
        }

        private async void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            if (this.pin.Text == this.pinReentry.Text)
            {
                this.Password = this.pin.Text;
                return;
            }

            var md = new MessageDialog("The password and password confirmation do not match.", "Password mismatch");
            await md.ShowAsync();
            args.Cancel = true;
        }

        public string Password { get; private set; }

        private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
        }

        private void ContentDialog_Opened(ContentDialog sender, ContentDialogOpenedEventArgs args)
        {
            this.pin.Focus(FocusState.Keyboard);
        }
    }
}
